package com.efast.dmom.equipment.service.repair.impl;

import com.efast.cafe.commponent.query.service.impl.QueryServiceImpl;
import com.efast.cafe.framework.bean.QueryPageBase;
import com.efast.cafe.framework.bean.TemplateParameter;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.cafe.portal.bean.query.QueryBean;
import com.efast.cafe.portal.bean.query.QueryConditionBean;
import com.efast.cafe.util.StringUtil;
import com.efast.dmom.equipment.bean.EquipmentMaintainQueryBean;
import com.efast.dmom.equipment.bean.EquipmentRepairQueryBean;
import com.efast.dmom.equipment.dao.maintain.EquipMaintainDao;
import com.efast.dmom.equipment.dao.repair.EquipRepairOrderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Map;

/**
 * 重写维修单据通用查询
 * @author Administrator
 *
 */
@Service("apiindex569-811")
public class EquipmentRepairQueryServiceImpl extends QueryServiceImpl{
	
	@Autowired
	private EquipRepairOrderDao equipRepairOrderDao;

	@Override
	public Object queryList(QueryBean querys) {
		QueryPageBase result = new QueryPageBase();
		QueryConditionBean bean = querys.getQueryConditionBean();

		EquipmentRepairQueryBean query = new EquipmentRepairQueryBean();
		query.setStart(bean.getStart());
		query.setLength(bean.getLength());
		
		TemplateParameter templateParameter = this.handleQueryOps(querys).getParameter();
		if(templateParameter!=null && templateParameter.getMap()!=null){
			Map<String, Object> params = templateParameter.getMap();
			query.setEquipCode(params.get("ebi_equip_code")!=null ? params.get("ebi_equip_code").toString():null);
			query.setEquipName(params.get("ebi_equip_name")!=null ? params.get("ebi_equip_name").toString():null);
			query.setOrderNumber(params.get("ro_order_number")!=null ? params.get("ro_order_number").toString():null);
			query.setStatus(params.get("ro_status")!=null ? params.get("ro_status").toString():null);
		}
		if(!StringUtil.isNullOrBlank(query.getStatus())){
			query.setStatusList( Arrays.asList(query.getStatus().split("~")));
		}
		query.setCompanyCode(SpringWebUtils.getRequestCompany());
		query.setCurrentUser(SpringWebUtils.getRequestUser());
		query.setConfId(1010);//维修流程ID
		
		result.setResultList(equipRepairOrderDao.queryRepairOrderByPage(query));
		result.setTotalRows(equipRepairOrderDao.countRepairOrder(query));
		
		return result;
	}
	
}
